import {request} from "umi"
import {delNullProperty} from "@/utils/handle";

/**
 * 分页获取角色列表
 * @param params
 */
export function getRole(params: any) {
  delNullProperty(params)
  return request<ABIS.Pagination<ABIS.RoleVO>>(
    '/api/roles/page',
    {
      params
    }
  )
}

/**
 * 新增角色
 * @param label
 * @param role
 */
export function addRole(label: string, role: string) {
  return request<ABIS.Result<boolean>>(
    '/api/roles/add',
    {
      method: 'POST',
      data: {
        label,
        role
      },
      requestType: 'form'
    }
  )
}

/**
 * 改变角色状态
 * @param id
 * @param status
 */
export function flushStatus(id: (number | string)[], status: number = 0) {
  return request<ABIS.Result<boolean>>(
    '/api/roles/status',
    {
      method: "POST",
      data: {
        id,
        status
      },
      requestType: "form"
    }
  )
}

/**
 * 修改角色信息
 * @param id
 * @param label
 * @param role
 */
export function editRole(id: number, label: string, role: string) {
  return request<ABIS.Result<boolean>>(
    '/api/roles/edit',
    {
      method: 'PUT',
      data: {
        id,
        label,
        role
      },
      requestType: 'form'
    }
  )
}

/**
 * 删除角色
 * @param id
 */
export function delRole(id: (number | string)[]) {
  return request<ABIS.Result<boolean>>(
    '/api/roles/del',
    {
      method: 'DELETE',
      data: {
        id
      },
      requestType: 'form'
    }
  )
}
